package ${packageName};

import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.Data;

import java.util.List;
import java.util.function.Function;

@Data
public class PageResult<DO> {

    private List<DO> records;
    private long total;
    private long pageSize=10;
    private long current=1;
    private long totalPages;

    public static <T,R>PageResult<R> build(IPage<T> page, Function<List<T>,List<R>> function){
        if (page==null) return null;
        PageResult pageResult = new PageResult();
        pageResult.setRecords(function.apply(page.getRecords()));
        pageResult.setTotal(page.getTotal());
        pageResult.setPageSize(page.getSize());
        pageResult.setCurrent(page.getCurrent());
        pageResult.setTotalPages(page.getPages());
        return pageResult;
    }

    public static <T,R>PageResult<R> build(IPage<T> page){
        if (page==null) return null;
        PageResult pageResult = new PageResult();
        pageResult.setRecords((page.getRecords()));
        pageResult.setTotal(page.getTotal());
        pageResult.setPageSize(page.getSize());
        pageResult.setCurrent(page.getCurrent());
        pageResult.setTotalPages(page.getPages());
        return pageResult;
    }

}
